#!/bin/sh

set -e

TDIR=$1
MIRROR=$2
DISKNUM=$3
CDDIR=$4
ARCHES=$5

cd $CDDIR

fix_branding() {
    sed -i -e 's|Debian GNU/Linux|Kali Linux|g' \
	-e 's|Kali GNU/Linux|Kali Linux|g' \
	-e 's|Debian kali-rolling|Kali Rolling|g' \
	-e 's|Debian|Kali|g' \
	-e 's|DEBIAN|KALI|g' \
	"$@"
}

# Rebrand Debian into Kali
if [ -e ../boot$DISKNUM/isolinux/menu.cfg ]; then
    fix_branding ../boot$DISKNUM/isolinux/menu.cfg \
		 ../boot$DISKNUM/isolinux/*.txt
fi
if [ -d boot/grub/theme ] && [ -s boot/grub/theme ]; then
    fix_branding boot/grub/theme/*
fi
if [ -e autorun.inf ]; then
    fix_branding autorun.inf
fi

# Replace Debian specific documentation
rm -rf css
cat >README.txt <<EOF
This disc contains an installer for Kali Linux.

Read more at: https://www.kali.org
EOF
cat >README.html <<EOF
<html>
<head><title>Kali Linux Installer Disc</title></head>
<body>
This disc contains an installer for Kali Linux.

Read more at: <a href="https://www.kali.org">www.kali.org</a>
</body>
</html>
EOF

# Replace kali-last-snapshot with kali-rolling
if [ -e dists/kali-last-snapshot ]; then
    mv dists/kali-last-snapshot dists/kali-rolling
    rm -f dists/stable && ln -sf kali-rolling dists/stable
    sed -i -e 's|kali-last-snapshot|kali-rolling|g' \
	dists/kali-rolling/Release
fi

# Redo the md5sum.txt due to our changes
find . -type f | grep -v ./md5sum.txt | xargs md5sum | sort -uk2 > md5sum.txt
